//
//  MainTableViewCell2.m
//  QuickCure
//
//  Created by 雪中狼 on 9/13/16.
//  Copyright © 2016 haoge. All rights reserved.
//

#import "MainTableViewCell2.h"
#import "CaseModel.h"

@interface MainTableViewCell2()
@property(nonatomic,strong)UILabel *timeLabel;
@property(nonatomic,strong)UILabel *illnessTypeLeftLabel;
@property(nonatomic,strong)UILabel *illnessTypeRightLabel;
@property(nonatomic,strong)UILabel *basicTypeLeftLabel;
@property(nonatomic,strong)UILabel *basicTypeRightLabel;
@property(nonatomic,strong)UILabel *illnessDescribeLabel;
@property(nonatomic,strong)UIImageView *iconImageView;
@property(nonatomic,strong)UIView *lineView;
@property(nonatomic,strong)UIImageView *photoImage;

@end

@implementation MainTableViewCell2
-(UILabel *)timeLabel{
    if (_timeLabel ==nil) {
        _timeLabel = [[UILabel alloc]init];
    }
    return _timeLabel;
    
}
-(UILabel *)illnessTypeLeftLabel{
    if (_illnessTypeLeftLabel ==nil) {
        _illnessTypeLeftLabel = [[UILabel alloc]init];
    }
    return _illnessTypeLeftLabel;
    
}
-(UILabel *)illnessTypeRightLabel{
    if (_illnessTypeRightLabel ==nil) {
        _illnessTypeRightLabel = [[UILabel alloc]init];
    }
    return _illnessTypeRightLabel;
    
}
-(UILabel *)basicTypeLeftLabel{
    if (_basicTypeLeftLabel ==nil) {
        _basicTypeLeftLabel = [[UILabel alloc]init];
    }
    return _basicTypeLeftLabel;
    
}
-(UILabel *)basicTypeRightLabel{
    if (_basicTypeRightLabel ==nil) {
        _basicTypeRightLabel = [[UILabel alloc]init];
    }
    return _basicTypeRightLabel;
    
}
-(UILabel *)illnessDescribeLabel{
    if (_illnessDescribeLabel ==nil) {
        _illnessDescribeLabel = [[UILabel alloc]init];
    }
    return _illnessDescribeLabel;
    
}
-(UIView *)lineView{
    if (_lineView == nil) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithRed:49.0/255 green:199.0/255 blue:198.0/255 alpha:1];
        
    }
    return _lineView;
}

-(UIImageView *)iconImageView{
    if (_iconImageView == nil) {
        _iconImageView = [[UIImageView alloc]init];
        _iconImageView.image =[UIImage imageNamed:@"illness_rb_img_sel.png"];
    }
    return _iconImageView;
    
}
-(UIImageView *)photoImage{
    if (_photoImage == nil) {
        _photoImage = [[UIImageView alloc]init];
        _photoImage.image =[UIImage imageNamed:@"user_default"];
    }
    return _photoImage;

}
-(void)setModel:(CaseModel *)model{
    
    _model = model;
    
    self.illnessTypeRightLabel.text = model.illnessType;
    self.basicTypeRightLabel.text = model.basicType;
    self.timeLabel.text = model.time;
    self.photoImage.image =model.photoImage;
    if (model.illnessDescribe) {
        self.illnessDescribeLabel.text = model.illnessDescribe;
    }

}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}
-(void)setupUI{
    
    UIView *view =[[UIView alloc]init];
    [self.contentView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.contentView);
        
    }];
    
    
    [self.contentView bringSubviewToFront:view];
    //    view.backgroundColor = [UIColor redColor];
    view.userInteractionEnabled=YES;
    
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TableClick)];
    [view addGestureRecognizer:tap];

    
    [self.contentView addSubview:self.iconImageView];
    [self.contentView addSubview:self.lineView];
    [self.contentView addSubview:self.photoImage];
    
    [self.contentView addSubview:self.timeLabel];
    self.timeLabel.text=@"时间";
    [self.timeLabel setTextColor:[UIColor lightGrayColor]];
    
    [self.contentView addSubview:self.illnessDescribeLabel];
    self.illnessDescribeLabel.text =@"暂时没有描述";
    [self.illnessDescribeLabel setTextColor:[UIColor lightGrayColor]];
    self.illnessDescribeLabel.font = [UIFont systemFontOfSize:14];
    self.illnessDescribeLabel.numberOfLines = 2;

    
    
    [self.contentView addSubview:self.illnessTypeLeftLabel];
    self.illnessTypeLeftLabel.text = @"疾病类型:";
    [self.contentView addSubview:self.illnessTypeRightLabel];
    self.illnessTypeRightLabel.text = @"疾病类型描述";
    [self.illnessTypeRightLabel setTextColor:[UIColor lightGrayColor]];
    
    [self.contentView addSubview:self.basicTypeLeftLabel];
    self.basicTypeLeftLabel.text =@"基本类型:";
    //    [self.timeLabel setTextColor:[UIColor lightGrayColor]];
    
    [self.contentView addSubview:self.basicTypeRightLabel];
    self.basicTypeRightLabel.text = @"基本类型描述";
    [self.basicTypeRightLabel setTextColor:[UIColor lightGrayColor]];
    
  
    
    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(0);
        make.width.height.equalTo(15);
        make.leading.equalTo(self.contentView).offset(25);
    }];
    
    //线
    [self.lineView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView.mas_bottom).offset(0);
        make.leading.equalTo(self.iconImageView.centerX).offset(0);
        make.bottom.equalTo(self.contentView).offset(0);
        make.width.equalTo(@1);
    }];
    //时间
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.leading.equalTo(self.contentView).offset(50);
        make.trailing.equalTo(self.contentView).offset(-10);
    }];
    //头像
    [self.photoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@80);
        make.height.equalTo(@90);
        
        make.top.equalTo(self.timeLabel.mas_bottom).offset(10);
        make.leading.equalTo(self.contentView).offset(50);
        make.bottom.lessThanOrEqualTo(self.contentView).offset(-10);
    }];
    //疾病类型
    [self.illnessTypeLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.photoImage.mas_top).offset(0);
        make.left.equalTo(self.photoImage.mas_right).offset(10);
    }];
    //疾病类型内容
    [self.illnessTypeRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.photoImage.mas_top).offset(0);
        make.left.equalTo(self.illnessTypeLeftLabel.mas_right).offset(10);
    }];
    //基本类型
    [self.basicTypeLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.illnessTypeLeftLabel.mas_bottom).offset(10);
        make.leading.equalTo(self.photoImage.mas_trailing).offset(10);
    }];
    //基本类型内容
    [self.basicTypeRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.illnessTypeLeftLabel.mas_bottom).offset(10);
        make.leading.equalTo(self.basicTypeLeftLabel.mas_trailing).offset(10);
    }];
    //疾病状态
    [self.illnessDescribeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.basicTypeLeftLabel.mas_bottom).offset(5);
        make.leading.equalTo(self.photoImage.mas_trailing).offset(10);
        make.right.equalTo(self.contentView).offset(-10);

    }];

}
-(void)TableClick{
    if ([self.delegate performSelector:@selector(cover)]) {
        [self.delegate cover ];
    }
    
    
    
}

@end
